﻿using Microsoft.Extensions.Caching.Memory;

namespace Base.Structure.Cache
{
    public class CacheHelper : ICacheHelper
    {
        private readonly IMemoryCache _memoryCache;

        public CacheHelper(IMemoryCache memoryCache)
        {
            _memoryCache = memoryCache;
        }

        public async Task<T> GetCacheAsync<T>(string key)
        {
            _memoryCache.TryGetValue(key, out T value);
            return value;
        }

        public async Task SetCacheAsync<T>(string key, T value, TimeSpan expiration)
        {
            _memoryCache.Set(key, value, expiration);
        }

        public async Task RemoveCacheAsync(string key)
        {
            _memoryCache.Remove(key);
        }
    }
}
